package com.fin.zw.aiqas.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class ErrorController {

    private static final Logger log = LoggerFactory.getLogger(ErrorController.class);

    @GetMapping("/error")
    public void error(HttpServletResponse response, HttpServletRequest request) {
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if (statusCode == 401) {
            response.setStatus(401);
            log.info("401...");
        } else if (statusCode == 404) {
            response.setStatus(404);
            log.info("404...");
        } else if (statusCode == 403) {
            response.setStatus(403);
            log.info("403...");
        } else {
            response.setStatus(500);
            log.info("500...");
        }
    }

    @GetMapping("/power")
    public void power(HttpServletResponse response) {
        response.setStatus(403);
        log.info("403...");
    }
}
